package meta

import "encoding/json"

type Instance struct {
	Label         string `json:"label" yaml:"label" xorm:"label"`
	Guid          string `json:"guid" yaml:"guid" xorm:"guid"`
	Name          string `json:"name" yaml:"name" xorm:"name"`
	Platfrom      string `json:"platfrom" yaml:"platfrom" xorm:"platfrom"`
	InstanceValue string `json:"instance" yaml:"instance" xorm:"instance_json"`
}

type GlueInstance struct {
	Label      string `json:"label" yaml:"label" xorm:"label varchar(255) pk notnull unique('head')"`
	Version    string `json:"version" yaml:"version" xorm:"version varchar(15) default 'v0.0.1'"`
	Name       string `json:"name" yaml:"name" xorm:"name varchar(40) default 'what is the config name?'"`
	Describe   string `json:"describe" yaml:"describe" xorm:"describe varchar(40) default 'what is the config describe?'"`
	ConfigKind string `json:"kind" yaml:"kind" xorm:"kind varchar(20) default 'application'"`

	InstanceYaml       string `json:"instance_yaml" yaml:"instance_yaml" xorm:"instance_yaml TEXT"`
	InstanceServeLevel string `json:"instance_serve_level" yaml:"instance_serve_level " xorm:"instance_serve_level varchar(20) default 'bestEffort'"`
	InstanceType       string `json:"instance_type" yaml:"instance_type" xorm:"instance_type varchar(20) default 'container'"`

	InstanceGuid  string `json:"guid" yaml:"guid" xorm:"guid varchar(255) pk notnull unique('head')"`
	InstanceState string `json:"state" yaml:"state" xorm:"state varchar(20) default 'InConfiguration'"`
	InstanceNode  string `json:"node" yaml:"node" xorm:"node varchar(100)"`

	Tags string `json:"tags" yaml:"tags" xorm:"tags TEXT"`

	UserToken string `json:"user_token" yaml:"user_token" xorm:"user_token TEXT"`
}

func DeCodeTags(tag string) (map[string]string, error) {
	var tags map[string]string
	if err := json.Unmarshal([]byte(tag), &tags); err != nil {
		return nil, err
	}
	return tags, nil
}

type Containers struct {
	Containers map[string]Container `json:"containers" yaml:"containers"`
}

type Container struct {
	//Name     string            `json:"name" yaml:"name"`
	ImageTag string            `json:"image_tag" yaml:"image_tag"`
	Runtime  string            `json:"runtime" yaml:"runtime"`
	Workdir  string            `json:"workdir" yaml:"workdir"`
	Cmds     []string          `json:"cmds" yaml:"cmds"`
	Envs     map[string]string `json:"envs" yaml:"envs"`
	Ports    map[string]string `json:"ports" yaml:"ports"`
	Mounts   map[string]string `json:"mounts" yaml:"mounts"`

	CpuSet string `json:"cpu_set" yaml:"cpu_set"`
	Memory string `json:"memory" yaml:"memory"`
	Cpu    string `json:"cpu" yaml:"cpu"`

	ServicPerfix string `json:"servic_perfix" yaml:"servic_perfix"`
	ReportEnable bool   `json:"report_enable" yaml:"report_enable"`

	DependsOn      []string          `json:"depends_on" yaml:"depends_on"`
	ScheduleLabels map[string]string `json:"schedule_labels" yaml:"schedule_labels"`
}
